package com.fr.report.script.function;

import com.fr.base.FRContext;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FArray;
import java.util.logging.Level;
import java.util.logging.Logger;

public class GETARRAYELEMENT extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length != 2)
      return Primitive.ERROR_NAME;
    Object localObject = paramArrayOfObject[0];
    if (!(localObject instanceof FArray))
      return Primitive.ERROR_NAME;
    try
    {
      if (localObject instanceof FArray)
      {
        FArray localFArray = (FArray)paramArrayOfObject[0];
        try
        {
          return localFArray.elementAt(Integer.parseInt(paramArrayOfObject[1].toString()) - 1);
        }
        catch (ArrayIndexOutOfBoundsException localArrayIndexOutOfBoundsException)
        {
          FRContext.getLogger().log(Level.WARNING, localArrayIndexOutOfBoundsException.getMessage(), localArrayIndexOutOfBoundsException);
          return Primitive.ERROR_VALUE;
        }
      }
    }
    catch (NumberFormatException localNumberFormatException)
    {
      FRContext.getLogger().log(Level.WARNING, localNumberFormatException.getMessage(), localNumberFormatException);
      return Primitive.ERROR_VALUE;
    }
    return null;
  }

  public Function.Type getType()
  {
    return Function.ARRAY;
  }

  public String getCN()
  {
    return "GETARRAYELEMENT(array, index):函数返回数组array的第index个元素。\n示例：\nString[] array = {\"a\", \"b\", \"c\", \"d\"}\nGETARRAYELEMENT(array, 3)等于c.\nGETARRAYELEMENT(array, 1)等于a.";
  }

  public String getEN()
  {
    return "GETARRAYELEMENT(array, index):Returns the index element of the array.\nExample:\nString[] array = {\"a\", \"b\", \"c\", \"d\"}\nGETARRAYELEMENT(array, 3)equals c.\nGETARRAYELEMENT(array, 1)equals a.";
  }
}